import frida
import requests
import json

def on_message(message, data):
    if message['type'] == 'send':
        payload = message['payload']
        if payload['action'] == 'post':
            response = requests.post(payload['url'], json=payload['data'])
            script.post({'action': 'postResult', 'data': response.text})

if __name__ == '__main__':
    device = frida.get_usb_device()
    pid = device.spawn(["com.tencent.mm"])
    device.resume(pid)
    session = device.attach(pid)

    script = session.create_script(open("_agent.js").read())
    script.on('message', on_message)
    script.load()

    # Keep the Python script running
    import time
    while True:
        time.sleep(1)
